import Vue from "vue";
import Router from "vue-router";
import Home from "./views/Home.vue";
import about from "./views/About.vue"
import NotFound from './views/404'
Vue.use(Router);
console.log("999",process.env.BASE_URL)
export default new Router({
  // mode: "history",
  base: process.env.BASE_URL,
  routes: [
    {
      path:'/index',
      name:'index',
      component: Home,
      meta: {
        keepAlive: true // 缓存
      }
    },
    {
      path:"/index.html",
      redirect: "/index"
    },
    {
      path:"/diancan",
      redirect: "/index"
    },
    {
      path: "/",
      redirect: "/index",
    },
    // {
    //   path:"/重定向",
    //   redirect:"/about"
    // },
    {
      path:"/cart",
      name:"cart",
      component:()=>import ("./views/cart.vue")
    },
    {
      path:"/user",
      name:"user",
      component: () => import ("./views/user.vue"),
      meta: {
        keepAlive: true // 缓存
      },
      children:[
        {
          path:":userName"
        }
      ]
    },
    {
      path: "/about",
      name: "about",
      // route level code-splitting
      // this generates a separate chunk (about.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      component: () => import (/* webpackChunkName: "about" */ "./views/About.vue")
    },
    {
      path:"/category",
      name:"category",
      component:() => import ("./views/Category.vue"),
      children:[
        {
          path:"about",
          name:"关于",
          component:about
        }
      ]
/*       component:() => ({
        // 需要加载的组件 (应该是一个 `Promise` 对象)
        component: import('./views/Category.vue'),
        // 异步组件加载时使用的组件(loading层)
        loading: LoadingComponent,
        // 加载失败时使用的组件
        error: ErrorComponent,
        // 展示加载时组件的延时时间。默认值是 200 (毫秒)
        delay: 200,
        // 如果提供了超时时间且组件加载也超时了，
        // 则使用加载失败时使用的组件。默认值是：`Infinity`
        timeout: 3000
      }) */
    },
    {
      path:'*',
      name:'NotFound',
      component:() => import ('./views/404')
    }
  ]
});
